<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Commit a transaction</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.cubrid-column-types.html">cubrid_column_types</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.cubrid-connect-with-url.html">cubrid_connect_with_url</a></div>
 <div class="up"><a href="ref.cubrid.html">CUBRID 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.cubrid-commit" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">cubrid_commit</h1>
  <p class="verinfo">(PECL CUBRID &gt;= 8.3.0)</p><p class="refpurpose"><span class="refname">cubrid_commit</span> &mdash; <span class="dc-title">Commit a transaction</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.cubrid-commit-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>cubrid_commit</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$conn_identifier</code></span> )</div>

  <p class="para rdfs-comment">
    The <span class="function"><strong>cubrid_commit()</strong></span> function is used to execute commit
    on the transaction pointed by <em><code class="parameter">conn_identifier</code></em>,
    currently in progress. Connection to the server is closed after the
    <span class="function"><strong>cubrid_commit()</strong></span> function is called; However, 
    the connection handle is still valid.
  </p>
  <p class="para">
   In CUBRID PHP, auto-commit mode is disabled by default for transaction management. 
   You can set it by using <span class="function"><a href="function.cubrid-set-autocommit.html" class="function">cubrid_set_autocommit()</a></span>. 
   You can get its status by using <span class="function"><a href="function.cubrid-get-autocommit.html" class="function">cubrid_get_autocommit()</a></span>. Before you start a transaction, 
   remember to disable the auto-commit mode.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.cubrid-commit-parameters">
 <h3 class="title">参数</h3>
 <p class="para">
  <dl>

    
     <dt>
<em><code class="parameter">conn_identifier</code></em></dt>

     <dd>
<p class="para">Connection identifier.</p></dd>

   
  </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.cubrid-commit-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
    <strong><code>TRUE</code></strong>, when process is successful.
  </p>
    <p class="para">
    <strong><code>FALSE</code></strong>, when process is unsuccessful.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.cubrid-commit-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-981">
   <p><strong>Example #1 <span class="function"><strong>cubrid_commit()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">33000</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"demodb"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"dba"</span><span style="color: #007700">);<br /><br />@</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"DROP&nbsp;TABLE&nbsp;publishers"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$sql&nbsp;</span><span style="color: #007700">=&nbsp;&lt;&lt;&lt;EOD<br /></span><span style="color: #DD0000">CREATE&nbsp;TABLE&nbsp;publishers(<br />pub_id&nbsp;CHAR(3),&nbsp;<br />pub_name&nbsp;VARCHAR(20),&nbsp;<br />city&nbsp;VARCHAR(15),&nbsp;<br />state&nbsp;CHAR(2),&nbsp;<br />country&nbsp;VARCHAR(15)<br />)<br /></span><span style="color: #007700">EOD;<br /></span><span style="color: #0000BB">cubrid_set_autocommit</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,</span><span style="color: #0000BB">false</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sql</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"Error&nbsp;facility:&nbsp;%d\nError&nbsp;code:&nbsp;%d\nError&nbsp;msg:&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">cubrid_error_code_facility</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">cubrid_error_code</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">cubrid_error_msg</span><span style="color: #007700">());<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_disconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />}<br /><br /></span><span style="color: #0000BB">$req&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"INSERT&nbsp;INTO&nbsp;publishers&nbsp;VALUES(?,&nbsp;?,&nbsp;?,&nbsp;?,&nbsp;?)"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$id_list&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"P01"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"P02"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"P03"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"P04"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$name_list&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"Abatis&nbsp;Publishers"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Core&nbsp;Dump&nbsp;Books"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Schadenfreude&nbsp;Press"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Tenterhooks&nbsp;Press"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$city_list&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"New&nbsp;York"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"San&nbsp;Francisco"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Hamburg"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Berkeley"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$state_list&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"NY"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"CA"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"CA"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$country_list&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"USA"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"USA"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Germany"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"USA"</span><span style="color: #007700">);<br /><br />for&nbsp;(</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$size&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$id_list</span><span style="color: #007700">);&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">&lt;&nbsp;</span><span style="color: #0000BB">$size</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$i</span><span style="color: #007700">++)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$id_list</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$name_list</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$city_list</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$state_list</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$country_list</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">]);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!(</span><span style="color: #0000BB">$ret&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">)))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br />if&nbsp;(!</span><span style="color: #0000BB">$ret</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_rollback</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_commit</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$req&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;*&nbsp;FROM&nbsp;publishers"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(</span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_fetch_assoc</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-3s&nbsp;%-20s&nbsp;%-15s&nbsp;%-3s&nbsp;%-15s\n"</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$result</span><span style="color: #007700">[</span><span style="color: #DD0000">"pub_id"</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$result</span><span style="color: #007700">[</span><span style="color: #DD0000">"pub_name"</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$result</span><span style="color: #007700">[</span><span style="color: #DD0000">"city"</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$result</span><span style="color: #007700">[</span><span style="color: #DD0000">"state"</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$result</span><span style="color: #007700">[</span><span style="color: #DD0000">"country"</span><span style="color: #007700">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">cubrid_disconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
P01 Abatis Publishers    New York        NY  USA            
P02 Core Dump Books      San Francisco   CA  USA            
P03 Schadenfreude Press  Hamburg             Germany        
P04 Tenterhooks Press    Berkeley        CA  USA            
</pre></div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.cubrid-commit-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
   <li class="member"><span class="function"><a href="function.cubrid-rollback.html" class="function" rel="rdfs-seeAlso">cubrid_rollback()</a> - Roll back a transaction</span></li>
   <li class="member"><span class="function"><a href="function.cubrid-get-autocommit.html" class="function" rel="rdfs-seeAlso">cubrid_get_autocommit()</a> - Get auto-commit mode of the connection</span></li>
   <li class="member"><span class="function"><a href="function.cubrid-set-autocommit.html" class="function" rel="rdfs-seeAlso">cubrid_set_autocommit()</a> - Set autocommit mode of the connection</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.cubrid-column-types.html">cubrid_column_types</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.cubrid-connect-with-url.html">cubrid_connect_with_url</a></div>
 <div class="up"><a href="ref.cubrid.html">CUBRID 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
